//
//  ListViewController.swift
//  LLBBaseVC_Example
//
//  Created by Yun on 2018/11/1.
//  Copyright © 2018 CocoaPods. All rights reserved.
//

import UIKit
import LLBBaseVC
import Toast_Swift
import LLBUtil

class ListViewController: LLBBaseTableViewController {
    
    var count = 0

    override func viewDidLoad() {
        super.viewDidLoad()
        self.navigationItem.title = "新闻列表"
        setUpUi()
    }
    
    func setUpUi() {
        setTableViewWithType(style: .grouped)
        tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
        
        showHeaderRefreshWithAction()
        showFooterRefreshWithAction()
    }
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        showEmptyView(title: "没有数据了")
    }
    
    override func headerRefreshAction() {
        self.stopRefresh()
        self.tableView.mj_footer.isHidden = false
        count = 30
        tableView.reloadData()
        showHud()
        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now()+3) {
            self.hideHud()
        }
        
    }
    
    override func footerRefreshAction() {
        self.stopRefresh()
        self.tableView.mj_footer.isHidden = true
    }

    // MARK: - TableView
    override func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return count
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell")
        cell?.textLabel?.text = "Hello \(indexPath.row)"
        return cell!
    }
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
//        indexPath.row % 2 == 0 ? showErrorMessage("这个是错误的信息") : showSucessMessage("这个是成功的消息")
        showWarningMessage("这个是警告了")
    }
}
